﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Configuration;

namespace DIProject.ReceptionGoods
{	public partial class SupplierReturnRpt1 : Form
	{	private int docId;
		private string textFormat;

		public SupplierReturnRpt1() : this(0)
		{
		}
		public SupplierReturnRpt1(int docId)
		{	InitializeComponent();
			this.docId = docId;
			textFormat = Text;
		}

		private DIProject.DataSets.Reports reports = new DIProject.DataSets.Reports();
		private DIProject.DataSets.ReportsTableAdapters.Torg12_InfoTableAdapter infoTableAdapter = new DIProject.DataSets.ReportsTableAdapters.Torg12_InfoTableAdapter();
		private DIProject.DataSets.ReportsTableAdapters.Torg12_SupplierReturnTableAdapter dataTableAdapter = new DIProject.DataSets.ReportsTableAdapters.Torg12_SupplierReturnTableAdapter();
		private DIProject.Reports.Torg12.DataSet torg12DataSet = new DIProject.Reports.Torg12.DataSet();

		private void SupplierReturnRpt1_Load(object sender, EventArgs e)
		{	try
			{	Torg12.FileName = Path.Combine(ConfigurationManager.AppSettings["ReportsPath"], "Torg12/CrystalReport.rpt");
				Torg12.Load();
			}
			catch(SqlException eq)
			{	MessageBox.Show(this, string.Format("{0} ({1}): {2}", eq.Procedure, eq.LineNumber, eq.Message), Properties.Resources.strError, MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
			catch(Exception ex)
			{	MessageBox.Show(this, ex.Message, Properties.Resources.strError, MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
		}

		private void Torg12_InitReport(object sender, EventArgs e)
		{	try
			{	Torg12.SetDataSource(torg12DataSet);
			}
			catch(SqlException eq)
			{	MessageBox.Show(this, string.Format("{0} ({1}): {2}", eq.Procedure, eq.LineNumber, eq.Message), Properties.Resources.strError, MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
			catch(Exception ex)
			{	MessageBox.Show(this, ex.Message, Properties.Resources.strError, MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
		}

		private void Torg12_RefreshReport(object sender, EventArgs e)
		{	try
			{	torg12DataSet.Clear();
				infoTableAdapter.Fill(reports.Torg12_Info, docId);
					for(int i = 0, n = reports.Torg12_Info.Count; i < n; ++i)
						torg12DataSet.Info.Rows.Add(reports.Torg12_Info[i].ItemArray);
				dataTableAdapter.Fill(reports.Torg12_SupplierReturn, docId);
					for(int i = 0, n = reports.Torg12_SupplierReturn.Count; i < n; ++i)
						torg12DataSet.Data.Rows.Add(reports.Torg12_SupplierReturn[i].ItemArray);
				if(reports.Torg12_Info.Count > 0)
				{	DIProject.DataSets.Reports.Torg12_InfoRow info = reports.Torg12_Info[0];
					Text = string.Format(textFormat, info.Number, info.Date);
				}
			}
			catch(SqlException eq)
			{	MessageBox.Show(this, string.Format("{0} ({1}): {2}", eq.Procedure, eq.LineNumber, eq.Message), Properties.Resources.strError, MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
			catch(Exception ex)
			{	MessageBox.Show(this, ex.Message, Properties.Resources.strError, MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
		}
	}
}